//
//  FeedbackView.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/9/29.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit

class FeedbackView: UIView {

    fileprivate let placeholderLabel = UILabel()
    fileprivate let addLabel = UILabel()
    
    let contactView = PWInputView()
    let textView = UITextView()
    let submitBtn = UIButton()
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.backgroundColor = UIColor.mineColor()
        
        contactView.textView.isSecureTextEntry = false
        contactView.text = contactInformation
        contactView.placeholder = inputContactInformation
        self.addSubview(contactView)
        
        textView.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        textView.delegate = self
        self.addSubview(textView)
        
        placeholderLabel.text = talkYourSuggestForUs
        placeholderLabel.textColor = UIColor.gray
        placeholderLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        textView.addSubview(placeholderLabel)
        
        submitBtn.backgroundColor = UIColor.pinkColor()
        submitBtn.setTitle(submit_title, for: .normal)
        submitBtn.titleLabel?.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        submitBtn.layer.cornerRadius = 5
        submitBtn.layer.masksToBounds = true
        self.addSubview(submitBtn)
        
        addLabel.numberOfLines = 0
        addLabel.text = addUs
        addLabel.textAlignment = .center
        addLabel.textColor = UIColor.gray
        addLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 14))
        self.addSubview(addLabel)
        
        contactView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(RATIO_H(maxNum: 20))
            make.left.right.equalToSuperview()
            make.height.equalTo(RATIO_H(maxNum: 50))
        }
        
        textView.snp.makeConstraints { (make) in
            make.top.equalTo(contactView.snp.bottom).offset(RATIO_H(maxNum: 30))
            make.left.right.equalToSuperview()
            make.height.equalTo(RATIO_H(maxNum: 200))
        }
        
        placeholderLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(RATIO(maxNum: 5))
            make.top.equalToSuperview().offset(RATIO_H(maxNum: 5))
            make.right.equalToSuperview().offset(RATIO(maxNum: -5))
            make.height.greaterThanOrEqualTo(10)
        }
        
        submitBtn.snp.makeConstraints { (make) in
            make.top.equalTo(textView.snp.bottom).offset(RATIO_H(maxNum: 20))
            make.left.equalToSuperview().offset(RATIO(maxNum: 20))
            make.right.equalToSuperview().offset(RATIO(maxNum: -20))
            make.height.equalTo(RATIO_H(maxNum: 40))
        }
        
        addLabel.snp.makeConstraints { (make) in
            make.left.equalTo(submitBtn)
            make.right.equalTo(submitBtn)
            make.top.equalTo(submitBtn.snp.bottom).offset(RATIO_H(maxNum: 20))
            make.height.greaterThanOrEqualTo(10)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

extension FeedbackView : UITextViewDelegate {
    
    //MARK: 当文本发生变化时
    func textViewDidChange(_ textView: UITextView) {
        
        if textView.text == "" {
            placeholderLabel.isHidden = false
        }else{
            placeholderLabel.isHidden = true
        }
    }
}
